package com.example.application.views.deliverytimequery;

import com.example.application.bean.ShowInfo;
import com.example.application.service.SqlService;
import com.example.application.views.main.MainView;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.dependency.CssImport;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.router.RouteAlias;

@Route(value = "query", layout = MainView.class)
@PageTitle("订单查询")
@CssImport("./styles/views/deliverytimequery/deliverytimequery-view.css")
@RouteAlias(value = "", layout = MainView.class)
public class DeliverytimequeryView extends HorizontalLayout {

    private TextField DEMAND_SEASON;
    private TextField DEMAND_CHANNEL_GRP;
    private TextField MDLDESC;
    private TextField PLNGCTRYCD;

    private Button query;
    private Grid<ShowInfo> grid;
    private SqlService service;
    public DeliverytimequeryView() {
        setId("deliverytimequery-view");
        DEMAND_SEASON=new TextField("DEMAND_SEASON");
        DEMAND_CHANNEL_GRP=new TextField("DEMAND_CHANNEL_GRP");
        MDLDESC=new TextField("MDLDESC");
        PLNGCTRYCD=new TextField("PLNGCTRYCD");
        query = new Button("查询");;
        grid = new Grid<>(ShowInfo.class,true);
        service=new SqlService();
        add(DEMAND_SEASON,
            DEMAND_CHANNEL_GRP,
            MDLDESC,
            PLNGCTRYCD,
            query
            ,grid);
        setVerticalComponentAlignment(
            Alignment.END,
            DEMAND_SEASON,
            DEMAND_CHANNEL_GRP,
            MDLDESC,
            PLNGCTRYCD,
            query
            ,grid);

        grid.setVisible(true);
    query.addClickListener(
        e -> grid.setItems(SqlService.InfoToShowInfo(
            service.selectWhere(
                DEMAND_SEASON.getValue(),
                DEMAND_CHANNEL_GRP.getValue(),
                MDLDESC.getValue(),
                PLNGCTRYCD.getValue()))));
    }

}
